package com.minefinder;

import android.media.AudioManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
	final static int ACT_OPTIONS = 0;
	
	String level = OptionsActivity.LEVEL_EASY;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// set volume
		setVolumeControlStream(AudioManager.STREAM_MUSIC);
		
		// start button
		Button btnStartGame = (Button) findViewById(R.id.btn_start);
		btnStartGame.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this, GameActivity.class);
				intent.putExtra(OptionsActivity.LEVEL_STRING, level);
				startActivity(intent);
			}
		});

		// option button
		Button btnOptions = (Button) findViewById(R.id.btn_options);
		btnOptions.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this, OptionsActivity.class);
				intent.putExtra(OptionsActivity.LEVEL_STRING, level);
				startActivityForResult(intent, ACT_OPTIONS);
			}
		});

		// score button
		Button btnScore = (Button) findViewById(R.id.btn_score);
		btnScore.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this, ScoreActivity.class);
				intent.putExtra(OptionsActivity.LEVEL_STRING, level);
				startActivity(intent);
			}
		});
	}
	
	// get options result
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (requestCode) {
		case ACT_OPTIONS:
			if (resultCode == RESULT_OK) {
				this.level = data.getStringExtra(OptionsActivity.LEVEL_STRING);
			}
			//Log.i("level", this.level);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
}
